package com.bocek.chakmapoint.model;

import static org.junit.Assert.*;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;

import org.junit.*;

public class CTextTest {
	CText test;

	@Before
	public void setUp() {
		test = new CText();
		test.setValue("Test Text");
		test.move(new Point(10, 20));
		assertTrue(test.repOK());
	}

// Testing if the object has the correct type name
	@Test
	public void test_getName() {
		assertEquals(test.getName(), "Text");
	}

// Black Box Test of isPointInside() Method
	@Test
	public void test_isPointInside() {
		Point p = new Point(12, 21);
		assertTrue(test.repOK());
		assertTrue(test.isPointInside(p));

		p.setLocation(12, 50);
		assertTrue(test.repOK());
		assertFalse(test.isPointInside(p));

		p.setLocation(70, 21);
		assertTrue(test.repOK());
		assertFalse(test.isPointInside(p));
		
		test.setValue("Even a longer Test Text");
		assertTrue(test.repOK());
		assertTrue(test.isPointInside(p));		
	}

//	Black Box Test of Text Selection
	@Test
	public void test_select() {
		Point p = new Point(12, 21);
		test.select(p);
		assertTrue(test.repOK());
		assertTrue(test.isSelected());
		test.deselect();
		assertTrue(test.repOK());
		assertFalse(test.isSelected());

		p.setLocation(12, 50);
		test.select(p);
		assertTrue(test.repOK());
		assertFalse(test.isSelected());
	}
	
//	Black Box Test of various text value changers
	@Test
	public void test_change() {
		assertEquals(test.getFontType(), "Verdana");
		assertEquals(test.getFontStyle(), Font.PLAIN);
		assertEquals(test.getFontSize(), 10);

		test.changeFont("Arial", Font.BOLD, 12);
		assertTrue(test.repOK());
		
		assertEquals(test.getFontType(), "Arial");
		assertEquals(test.getFontStyle(), Font.BOLD);
		assertEquals(test.getFontSize(), 12);

		test.changeFontType("Times New Roman");
		test.changeFontStyle(Font.ITALIC);
		test.changeFontSize(14);
		assertTrue(test.repOK());
		
		assertEquals(test.getFontType(), "Times New Roman");
		assertEquals(test.getFontStyle(), Font.ITALIC);
		assertEquals(test.getFontSize(), 14);
	}
	
//	Black Box Test of isOutsideFrame method
	@Test
	public void test_isOutsideFrame()
	{
		Dimension testDimension = new Dimension(100, 100);
		assertFalse(test.isOutsideFrame(testDimension));
		
		test.move(new Point(-20, 0));
		assertTrue(test.repOK());
		assertTrue(test.isOutsideFrame(testDimension));		
		
		test.move(new Point(20, -20));
		assertTrue(test.repOK());
		assertTrue(test.isOutsideFrame(testDimension));		
		
		test.move(new Point(0, 20));
		assertTrue(test.repOK());
		testDimension = new Dimension(40, 100);
		assertTrue(test.isOutsideFrame(testDimension));
				
		testDimension = new Dimension(100, 20);
		assertTrue(test.isOutsideFrame(testDimension));

		testDimension = new Dimension(100, 100);
		test.move(new Point(0, 20));
		assertTrue(test.repOK());
		assertFalse(test.isOutsideFrame(testDimension));
	}
}
